package personal.xjl.studentdemo.dao;

import org.apache.ibatis.annotations.*;
import org.springframework.web.bind.annotation.RequestParam;
import personal.xjl.studentdemo.entity.Course;
import personal.xjl.studentdemo.entity.Teacher;

import java.util.List;

@Mapper
public interface TeacherMapper {
    @Delete("delete from teacher where id=#{id}")
    int deleteByPrimaryKey(@Param("id") Integer id);

    @Select("select *from teacher")
    List<Teacher> findAll();
     @Select("select * from teacher where name=#{username} and password=#{password}")
    List<Teacher> selectByUsernameAndPassword(@Param("username") String username,@Param("password") String password);
    @Insert("insert into teacher(id, name, password, sex, course_id, birthday,professional) values(#{id},#{name},#{password},#{sex},#{course_id},#{birthday},#{professional})")
    int insert(Teacher teacher);
   @Select("select * from teacher where id=#{id}")
    Teacher selectById(@Param("id") int id);
    @Update("update teacher set name=#{name},password=#{password},sex=#{sex},course_id=#{course_id},birthday=#{birthday},professional=#{professional} where id=#{id}")
    void update(Teacher teacher);
    @Select("select *from teacher limit #{fromIndex},#{pageSize}")
    //扩展了结果集，多了课程对象
    @Results({
            @Result(column = "course_id",property = "course",javaType = Course.class,
            one = @One(select = "personal.xjl.studentdemo.dao.CourseMapper.getCourseById"))
    })
    List<Teacher> selectByPage(@Param("fromIndex") int fromIndex, @Param("pageSize") int pageSize);
}
